<script>
    var defDep = '{{.backenduser.DepartmentId}}';
    $('#confirm').click(function () {

        var fromdep = $('#fromdep').val();
        var targetdep = $('#targetdep').val();
        var remarks = $('#remarks').val();
        if (fromdep == '') {
            layer.alert("请选择调出门店");
            return false;
        }
        if (targetdep == '') {
            layer.alert("请选择调入门店");
            return false;
        }
        if (fromdep == targetdep) {
            layer.alert("同一门店不需要调拨");
            return false;
        }

        var fromdep_name = $('#fromdep :selected').text();
        var targetdep_name = $('#targetdep :selected').text();

        $.post('{{ urlfor "AllocationController.ChooseTrader" }}', {
            'fromdep': fromdep,
            'fromdep_name': fromdep_name,
            'targetdep': targetdep,
            'targetdep_name': targetdep_name,
            'remarks': remarks
        }, function (res) {
            if (res.code == 0) {
                parent.SelectChoosetraderRollBack(res.data);
                return true;
            } else {
                layer.msg(res.msg);
            }
        }, 'json');
    });
    //设置门店列表
    get_manage_departments(function (d) {
        var opt = [];
        if (d.length > 0) {
            opt.push('<option value="">请选择</option>');
            $.each(d, function (idx, val) {
                opt.push('<option value="' + val.Id + '">' + val.Name + '</option>');
            });
        }
        $('#fromdep').html(opt.join('')).val(defDep);

        $('#targetdep').html(opt.join(''));
    });
</script>